package com.glepoch.springbootsecuritymybatis.bean;


import com.glepoch.springbootsecuritymybatis.compoment.constant.statuscode.BaseStatusEnum;
import com.glepoch.springbootsecuritymybatis.compoment.constant.statuscode.NormalStatusCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @description: 统一响应数据实体类
 * @author: ygl
 * @time: 20201204
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
//@ApiModel(description = "统一响应数据实体类")

public class RespResultVO<T> extends BaseResultVO<T> {

    //@ApiModelProperty("响应数据体")
    private T data;

    //下面属性为导出的辅助属性
    //@ApiModelProperty("导出表头实体类的clazz")
    private Class sheetHeadClazz;
    //@ApiModelProperty("生成的工作簿（sheet）名称")
    private String sheetName;

    public RespResultVO(int code, String message, T data) {
        super(code, message);
        this.data = data;
    }

    public RespResultVO(int code, String message) {
        super(code, message);
    }

    public static <T> RespResultVO success(int code, String message, T data) {
        return new RespResultVO(code, message, data);
    }

    public static RespResultVO success(int code, String message) {
        return new RespResultVO(code, message);
    }

    public static RespResultVO success(String message) {
        return success(NormalStatusCode.SUCCESS.getCode(), message);
    }


    public static RespResultVO success(BaseStatusEnum baseStatusEnum) {
        return new RespResultVO(baseStatusEnum.getCode(), baseStatusEnum.getMessage());
    }

    public static RespResultVO success() {
        return new RespResultVO(NormalStatusCode.SUCCESS.getCode(), NormalStatusCode.SUCCESS.getMessage());
    }

    public static <T> RespResultVO success(T data) {
        return success(NormalStatusCode.SUCCESS.getCode(), NormalStatusCode.SUCCESS.getMessage(), data);
    }

    public static <T> RespResultVO fail(int code, String message, T date) {
        RespResultVO respResultVO = new RespResultVO(code, message);
        respResultVO.setData(date);
        return respResultVO;
    }

    public static RespResultVO fail(int code, String message) {
        return new RespResultVO(code, message);
    }

    public static RespResultVO fail(BaseStatusEnum baseStatusEnum) {
        return fail(baseStatusEnum.getCode(), baseStatusEnum.getMessage());
    }

    public static RespResultVO fail(String message) {
        return fail(NormalStatusCode.FAIL.getCode(), message);
    }

    public static RespResultVO fail() {
        return fail(NormalStatusCode.FAIL.getCode(), NormalStatusCode.FAIL.getMessage());
    }
}
